#include "RenzoUtil.h"

namespace Renzo
{
	Size rzSizeMake(int w, int h) { 
		Size s; 
		s.width = w; 
		s.height = h; 
		return s; 
	}

	unsigned __int64 rzStartCycles, rzEndCycles, rzOverheadCycles, rzElapsedCycles;
	extern const int numIterations = 10000;	// for const int, must put "extern" in both the original cpp and other cpp that uses it

	unsigned __int64 rzGetClockCycles() {	
		__asm {
			rdtsc
		}
		/*
		__asm {
			xor   eax,eax	          // VC won't realize that eax is modified w/out this
									  //   instruction to modify the val.
									  //   Problem shows up in release mode builds
			_emit 0x0F		          // Pentium high-freq counter to edx;eax
			_emit 0x31		          // only care about low 32 bits in eax

			xor   edx,edx	          // so VC gets that edx is modified
		}*/
	}


	void rzClockInit() {
		rzOverheadCycles = 0;
		for (int i = 0; i < numIterations; ++i) {
			rzStartCycles = rzGetClockCycles();
			rzEndCycles = rzGetClockCycles();
			rzOverheadCycles += rzEndCycles - rzStartCycles;
		}
		printf("Overhead: %I64u\n", rzOverheadCycles /= numIterations);
		rzStartCycles = rzGetClockCycles();	// prepare rzStartCycles for tick()
	}

	void rzClockTick() {		
		rzEndCycles = rzGetClockCycles();
		rzElapsedCycles = rzEndCycles - rzStartCycles - rzOverheadCycles;
		printf("Tick: %I64u\n", rzElapsedCycles);
		rzStartCycles = rzGetClockCycles();
	}



}